package com.peanut.bosskg.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

public class HtmlUtil {


    /**
     * 生成form表单html
     *
     * @param param
     * @param url
     * @return
     */
    public static String getFormHtml(Map param, String url) {
        StringBuffer formHtml = new StringBuffer();
        //组织form表单
        List<String> keys = new ArrayList<String>(param.keySet());
        String formId = "olpay".concat(UUID.randomUUID().toString().replace("-", ""));
        formHtml.append("<form name=\"" + formId + "\" action=\"" + url + "\" method=\"post\">");

        for (int i = 0; i < keys.size(); i++) {
            String name = keys.get(i);
            String value = String.valueOf(param.get(name));
            formHtml.append("<input type=\"hidden\" name=\"" + name + "\" value=\"" + value + "\"/>");
        }

        formHtml.append("<input type=\"submit\" value=\"" + "确认" + "\" style=\"display:none;\"></form>");
        formHtml.append("<script>document.forms[0].submit();</script>");

        return formHtml.toString();
    }

}
